package base

import (
	"gvm/rtda"
	"gvm/rtda/heap"
)

func InitClass(thread *rtda.JThread, klass *heap.Klass) {
	klass.StartInit()
	initSuperClass(thread, klass)
	scheduleClinit(thread, klass)

}

func initSuperClass(thread *rtda.JThread, klass *heap.Klass) {
	if !klass.IsInterface() {
		superClass := klass.SuperClass()
		if superClass != nil && !superClass.InitStarted() {
			InitClass(thread, superClass)
		}
	}
}

func scheduleClinit(thread *rtda.JThread, klass *heap.Klass) {
	clinit := klass.GetClinitMethod()
	if clinit != nil {
		newJFrame := thread.NewFrame(clinit)
		print(klass.Name() + "  init 方法入栈")
		thread.PushJFrame(newJFrame)
	}
}
